function getContextPath(){ 
	var pathName = document.location.pathname; 
	var index = pathName.substr(1).indexOf("/"); 
	var result = pathName.substr(0,index+1); 
	return result; 
}

$(function(){
	if ($("#inlineRadio1").is(":checked")){
		$("#rushStatus").text(0);
	}
	if ($("#inlineRadio2").is(":checked")){
		$("#rushStatus").text(1);
	}
	if ($("#inlineRadio3").is(":checked")){
		$("#rushStatus").text(2);
	}
	
	var beginTime = $("beginTime").text();
		
	$.validator.addMethod("checkEndTime",function(value){
		var myTime = Date.parse(beginTime.toString());
		var ApplyTime = Date.parse(value);
		if (ApplyTime > myTime){
			return true;
		} else {
			return false;
		}
	},"结束日期不能小于起始日期")
	
	$.validator.addMethod("checkBeginTime",function(value){
		var myTime = Date.parse(new Date().toLocaleDateString());
		var ApplyTime = Date.parse(value);
		if (ApplyTime <= myTime){
			return true;
		} else {
			return false;
		}		
	},"起始日期不能大于当前日期")
	
	$("#regForm").validate({
		rules:{
			taskTitle:{
				rangelength:[2,20]
			},
			beginTime:{
				checkBeginTime:true
			},
			endTime:{
				checkEndTime:true
			}
		},
		messages:{
			taskTitle:{
				rangelength:"请输入合法申请标题"
			},
			beginTime:{
				checkBeginTime:"起始日期不能大于当前日期"
			},
			endTime:{
				checkEndTime:"结束日期不能小于起始日期"
			}
		},
		submitHandler:function(){
			var params = $("[type='text']").serialize();
			var taskId = $("#taskId").text();
			$.post(getContextPath()+"/AddTask.oa?cmd=upd",params,function(data){
				if (data.code == 1){
					alert(data.msg);
					parent.location.href=getContextPath()+"/task/AddTask.jsp";
				} else {
					alert(data.msg);
				}
			},"json")
		},
	})
	
})